package main

import "fmt"

//#link: https://leetcode-cn.com/problems/xor-queries-of-a-subarray/
func main() {
	arr := []int{1, 3, 4, 8}
	queries := [][]int{
		{0, 1},
		{1, 2},
		{0, 3},
		{3, 3},
	}
	fmt.Println(xorQueries(arr, queries))
}

func xorQueries(arr []int, queries [][]int) []int {
	result := make([]int, len(queries))
	xors := make([]int, len(arr)+1)
	for index, value := range arr {
		xors[index+1] = xors[index] ^ value
	}

	for i, query := range queries {
		result[i] = xors[query[0]] ^ xors[query[1]+1]
	}
	return result
}
